#include <stdio.h>
#include <stdlib.h>
#include "LinkQueue.h"

#define true 1
#define false 0

//初始化
int LQueueInit(LQueue* lq)
{
    return DLlistInit(&lq->queue);
}

//打印队列
void LQueuePrint(LQueue* lq)
{
    Node* cur = lq->queue.head;
    while(cur != NULL)
    {
        printf("%d ", cur->data);
        cur = cur->next;
    }
    printf("\n");
}

//入队
void LQueuePush(LQueue* lq, ElementType element)
{
    DLlistInsertTail(&lq->queue, element);
}

//出队
ElementType* LQueuePop(LQueue* lq)
{
    if(lq->queue.len == 0)
    {
        printf("Queue is empty!\n");
        return NULL;
    }
    lq->FrontData = lq->queue.head->data;
    DLlistRemoveByIndex(&lq->queue, 0);
    return &lq->FrontData;
}

//销毁队列
void LQueueDestroy(LQueue* lq)
{
    DLlistDestroy(&lq->queue);
}

//判空
int LQueueIsEmpty(LQueue* lq)
{
    if(lq->queue.len == 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

//获取队首元素
ElementType LQueueGetFront(LQueue* lq)
{
    return lq->queue.head->data;
}

//获取队列有效元素个数
int LQueueSize(LQueue* lq)
{
    return lq->queue.len;
}



